//
//  YZQButtonCollectonController.m
//  A_project2.0
//
//  Created by apple on 16/3/15.
//  Copyright © 2016年 七平. All rights reserved.
//

#import "YZQButtonCollectonController.h"
#import <AFNetworking.h>
#import <UIImageView+AFNetworking.h>
#import "YZQButtonCollectionViewCell.h"
#import "YZQbuttonModel.h"
#import "YZQCityViewController.h"
#define WIDTH [UIScreen mainScreen].bounds.size.width
#define HEIGHT [UIScreen mainScreen].bounds.size.height

@interface YZQButtonCollectonController ()<UICollectionViewDataSource,UICollectionViewDelegate>
@property (nonatomic, strong) UICollectionView *collectionView;
@property (nonatomic, strong) NSMutableArray *dataArr;// 存放本页面国家中的每个城市


@end

@implementation YZQButtonCollectonController

- (void)viewDidLoad {
    [super viewDidLoad];

    
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    
    
    // 滚动方向
    //    layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
#pragma mark - collectionview 创建
    // cell 大小
    layout.itemSize = CGSizeMake((WIDTH - 30) / 2, (HEIGHT - 113) / 3);
    // 行列间距
    layout.minimumInteritemSpacing = 10;
    layout.minimumLineSpacing = 10;
    // 边界
    layout.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10);
    self.collectionView = [[UICollectionView alloc] initWithFrame:self.view.bounds collectionViewLayout:layout];
    _collectionView.delegate = self;
    _collectionView.dataSource = self;
    _collectionView.backgroundColor = [UIColor whiteColor];
    // 重用池
    [_collectionView registerClass:[YZQButtonCollectionViewCell  class] forCellWithReuseIdentifier:@"cell"];
    [self.view addSubview:_collectionView];


    
    // 数据处理
    [self data];
    

    // Do any additional setup after loading the view.
}
- (void)data
{
    [QPNetWorkingTool getNetWorkingTool:self.str dic:nil success:^(id result) {
        NSArray *arr = result[@"data"];
        self.dataArr = [YZQbuttonModel modelHanderWithArray:arr];
        
        [_collectionView reloadData];

    } fail:^(NSError *error) {
        
    }];
}
#pragma mark - cell的个数
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    
    
    return _dataArr.count;
}
#pragma mark - cell样式
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    YZQbuttonModel *m = _dataArr[indexPath.row];
    YZQButtonCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];

    cell.cnname.text = m.catename;
    cell.cnname.font = [UIFont systemFontOfSize:14];
    cell.cnname.textColor = [UIColor whiteColor];
    //    [cell.cnname NightWithType:UIViewColorTypeNormal];
    cell.enname.text = m.catename_en;
    cell.enname.font = [UIFont systemFontOfSize:14];
    cell.enname.textColor = [UIColor whiteColor];
    //    [cell.enname NightWithType:UIViewColorTypeNormal];
    [cell.imgView sd_setImageWithURL:[NSURL URLWithString:m.photo]placeholderImage:[UIImage imageNamed:@"zhanweitu.jpg"]];
    cell.beenstrLabel.text = m.beenstr;
    //    [cell NightWithType:UIViewColorTypeNormal];
    cell.beenstrLabel.textColor = [UIColor colorWithRed:137 /255.0 green:137 / 255.0 blue:137 /255.0 alpha:1];
    cell.beenstrLabel.font = [UIFont systemFontOfSize:14];
    cell.representativeLabel.text = m.representative;
    cell.representativeLabel.numberOfLines = 0;
    cell.representativeLabel.font = [UIFont systemFontOfSize:14];
    cell.representativeLabel.textColor = [UIColor colorWithRed:112 / 255.0 green:112 / 255.0 blue:112 / 255.0 alpha:1];
    
    return cell;
    
    
}
#pragma mark - cell点击
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    YZQbuttonModel *m = _dataArr[indexPath.row];
    YZQCityViewController *cityVC = [[YZQCityViewController alloc] init];
    
    cityVC.str = m.cid;
    
    [self.navigationController pushViewController:cityVC animated:YES];
    

    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
